# -*- coding: utf-8 -*-
# @Time: 2021/8/11 8:16
# @File: problem-13.py
# @DESC: https://leetcode-cn.com/problems/roman-to-integer/
# 罗马数字转整数

class Solution:
    def romanToInt(self, s: str) -> int:
        map = {
            "I": 1,
            "V": 5,
            "X": 10,
            "L": 50,
            "C": 100,
            "D": 500,
            "M": 1000
        }

        data = []
        for i in s:
            data.append(map[i])

        if len(data) > 1:
            for index, i in enumerate(data[:-1]):
                if i < data[index + 1]:
                    data[index] = 0 - i

        return sum(data)


input = "LVIII"

s = Solution()
r = s.romanToInt(input)
print(r)
